<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Propia and CHR Exercise
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial113.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial107.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc224">15.7</A>&nbsp;&nbsp;Propia and CHR Exercise</H2>
The problem is to implement three constraints, <CODE>and</CODE>, <CODE>or</CODE>
and <CODE>xor</CODE> 
in CHRs and, as a separate exercise, in Propia.
The constraints are specified as follows:
All boolean variables have domain {0,1}: 0 for 'false' and 1
for 'true'. 
<BLOCKQUOTE CLASS="quotation">
and(X,Y,Z) =def (X &amp; Y) = Z<BR>
or(X,Y,Z) =def (X or Y) = Z<BR>
xor(X,Y,Z) =def ((X &amp; -Y) or (-X &amp; Y)) = Z
</BLOCKQUOTE>
Suppose your constraints are called 
<CODE>cons_and</CODE>, <CODE>cons_or</CODE> and <CODE>cons_xor</CODE>
Now write enter the following procedure:

	<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#CCCCFF">
	<BLOCKQUOTE CLASS="quote"><PRE>
full_adder(I1,I2,I3,O1,O2) :-
    cons_xor(I1,I2,X1),
    cons_and(I1,I2,Y1),
    cons_xor(X1,I3,O1),
    cons_and(I3,X1,Y2),
    cons_or(Y1,Y2,O2).
</PRE></BLOCKQUOTE></TD>
</TR></TABLE>
The problem is solved if you enter the query:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
?- full_adder(I1,I2,0,O1,1).
</PRE></BLOCKQUOTE>
and get the correct answer.<BR>
<BR>
Note: you are not allowed to load the ic library nor to use search and
backtracking!<BR>
<BR>
<HR>
<A HREF="tutorial113.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial107.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
</BODY>
</HTML>
